import { get } from 'lodash'
export default (addons) => {
  const tieredAddon = addons.find(i => get(i, 'pricing.pricingModel') === 'tiered')
  if (tieredAddon) {
    const tiers = (get(tieredAddon, 'pricing.tiers') || []).sort((a, b) => b.price - a.price)
    if (tiers.length) {
      return tiers[0].price
    }
  }
  const unitAddon = addons.find(i => get(i, 'pricing.pricingModel') === 'per_unit' || get(i, 'pricing.pricingModel') === 'flat_fee')
  if (unitAddon) {
    return get(unitAddon, 'pricing.price')
  }
}
